#!/usr/bin/env python
# encoding: utf-8
'''
@author: zhaowenpeng
@contact: winston@peipeiyun.com
@software: garner
@file: fetch_code_oe.py
@time: 2020/8/11 2:44 下午
@desc:
'''

import sys
# sys.path.append('../../')

import os
import pandas as pd
import numpy

import time


from models.parts import Parts
for root,p,files in os.walk('/Users/carl/standar_data/standartools/scripts/cst_scripts/export/'):
    for fi in files:
        fi ='/'.join([root,fi])
        print(fi)
        df = pd.read_excel(fi)
        df.fillna('',inplace=True)
        df['OE号'] = df['OE号'].astype('str')
        for index, row in df.iterrows():
            print(row.to_dict())
            part = Parts()
            part.article_brand = row.to_dict()['品牌']
            part.input_name = row.to_dict()['零件名称']
            print(type(row.to_dict()['OE号']))
            if row.to_dict()['OE号'] is None:
                part.input_oe = ''
            else:
                part.input_oe = row.to_dict()['OE号'].replace('.','')
            part.code = row.to_dict()['产品编码']
            part.car_names = row.to_dict()['适用车型']
            part.save()


